package com.testGraph

import org.apache.spark._
import org.apache.log4j.{Level, Logger}
import org.apache.spark.{SparkContext, SparkConf}
import org.apache.spark.graphx._
import org.apache.spark.graphx.Graph._
import org.apache.spark.rdd.RDD
import org.apache.spark.graphx.util.GraphGenerators

/**
  * Created by Administrator on 2017/4/21 0021.
  */
object TestPagerank2 {
  def main(args: Array[String]): Unit = {
    //设置运行环境
    val conf = new SparkConf().setAppName("SimpleGraphX").setMaster("local")
    val sc = new SparkContext(conf)
    val graph = GraphLoader.edgeListFile(sc,"cit-HepTh.txt")
    val aaa = graph.inDegrees.reduce((a,b)=> if (a._2 > b._2) a else b)
//    println(aaa.asInstanceOf[AnyRef].getClass.getSimpleName)
//    println(aaa)
    val v = graph.pageRank(0.001).vertices
    val xxx = v.take(10)
//    println(xxx.asInstanceOf[AnyRef].getClass.getSimpleName)
//    for(x <- xxx){
//      println(x)
//    }
    val themostpop = v.reduce((a,b) => if (a._2 > b._2) a else b)
    println(themostpop.asInstanceOf[AnyRef].getClass.getSimpleName)
    println(themostpop)
  }
}
